In this notebook we plot the permutahedron of order 4 which is a 3-dimensional polyhedron living in a 4-dimensional space. It is defined as the convex hull of all permutations of $(0, 1, 2, 3)$.
In [1]:
using Combinatorics, Polyhedra
v = vrep(collect(permutations([0, 1, 2, 3])))
Out[1]:
To plot a polyhedron, we need both the H-representation and V-representation so we will need a library to do representation conversion. We choose CDD in floating point arithmetic.
In [2]:
using CDDLib
p4 = polyhedron(v, CDDLib.Library())
Out[2]:
The permutahedron lives in a 4-dimension space but is 3-dimensional as it is contained in the hyperplane $x_1 + x_2 + x_3 + x_4 = 0 + 1 + 2 + 3 = 6$. We choose an orthogonal basis of this hyperplane: $(1, -1, 0, 0)$, $(1, 1, -2, 0)$ and $(1, 1, 1, -3)$.
In [3]:
v1 = [1, -1, 0, 0]
v2 = [1, 1, -2, 0]
v3 = [1, 1, 1, -3];
We project the polyhedron in this basis to obtain a full dimensional 3-dimensional polyhedron living in a 3-dimensional space.
In [4]:
p3 = project(p4, [v1 v2 v3])
Out[4]:
To get a plottable object, we transform the polyhedron into a mesh as follows.
In [5]:
m = Polyhedra.Mesh(p3);
In [ ]:
using MeshCat
vis = Visualizer()
setobject!(vis, m)
IJuliaCell(vis)
In [ ]:
using Makie
mesh(m, color=:blue)
In [ ]:
using Makie
wireframe(m)
In [ ]: